package mongodb.general.operator.mongoHelper.db;

import mongodb.general.operator.mongoHelper.common.Page;
import mongodb.general.operator.mongoHelper.common.builder.SortBuilder;
import mongodb.general.operator.mongoHelper.reflection.SerializableFunction;
import mongodb.general.operator.mongoHelper.wrapper.CriteriaWrapper;

import java.util.List;

public interface MongoHelper {
    public <T> T findById(String id, Class<T> clazz);
    public <T> List<T> findListByIds(String[] ids, Class<T> clazz);
    public Long findAllCount(Class<?> clazz);
    public <T> T findOneByQuery(CriteriaWrapper criteriaWrapper, SortBuilder sortBuilder, Class<T> clazz);
    public <T> List<T> findListByQuery(CriteriaWrapper criteriaWrapper,
                                       SortBuilder sortBuilder,
                                       Class<T> clazz);
    public List<Object> findListByQuery(CriteriaWrapper criteriaWrapper,
                                       SortBuilder sortBuilder,
                                       String tableName);

    /**
     * 根据条件查找某个属性
     * @param criteriaWrapper
     * @param documentClass obj.class
     * @param property Constant::getId
     * @param propertyClass String.class
     * @param <T>
     * @param <R>
     * @param <E>
     * @return 列表
     */
    public <T, R, E> List<T> findPropertiesByQuery(CriteriaWrapper criteriaWrapper,
                                                   Class<?> documentClass,
                                                   SerializableFunction<E, R> property,
                                                   Class<T> propertyClass);
    /**
     * 这里没查询到数据就直接插入了，，如果是单独调插入，需要预先检查能否查到数据
     * @param object
     * @return
     */
    public String insertOrUpdate(Object object);

    public <T> void insertAll(List<T> list);

    public void updateById(Object object);
    /**
     * 根据id更新全部字段
     * @param object 对象
     */
    public void updateAllColumnById(Object object);

    public void deleteById(String id, Class<?> clazz);
    public void deleteByIds(List<String> ids, Class<?> clazz);
    /**
     * 获取Page
     *
     * @param page  分页
     * @param clazz 类
     * @return Page 分页
     */
    public <T> Page<T> findPage(Page<?> page, Class<T> clazz);
    public <T> Page<T> findPage(SortBuilder sortBuilder, Page<?> page, Class<T> clazz);
    public <T> Page<T> findPage(CriteriaWrapper criteriaWrapper, SortBuilder sortBuilder, Page<?> page, Class<T> clazz);
}
